/**
 * 封装uni的request
 */
// const baseUrl = 'https://szhwx.ypeport.com/index.php'
const baseUrl = "https://szh-test.ypeport.com/index.php"
// const baseUrl = 'http://121.62.23.47:100'
const tokens = uni.getStorageSync('tokens') || ''
export function request(url, method = "GET", data,config={}) {
 // data.token = '2321';
  return new Promise(function (resolve, reject) {
    uni.request({
      url:  baseUrl+url,
      data: data,
      method: method,
      header: {
        'Content-Type'  : 'application/json',
        'Content-Type'  : 'application/x-www-form-urlencoded',
		'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
		'tokens'		: tokens,
		'Access-Control-Max-Age': 86400,
      },
      success: function (res) {
        uni.hideLoading()
		if(res.statusCode==401) {
			uni.navigateTo({
				url:'/pages/index/index'
			})
			return 
		}
        resolve(res)
      },
      fail: function (err) {
       let msg=JSON.stringify(err)
        uni.showModal({
          title: msg,
          content:msg,
          showCancel: false
        });
        reject(err);
      }
    })
  });
}


